<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
/* <![CDATA[ */

table, td
{
    border-color: #666;
    border-style: solid;
}
table, th
{
    border-color: #666;
    border-style: solid;
}

table
{
    border-width: 0 0 1px 1px;
    border-spacing: 0;
    border-collapse: collapse;
}

td
{
    margin: 0;
    padding: 8px;
    border-width: 1px 1px 0 0;
}
th
{
    margin: 0;
    padding: 8px;
    border-width: 1px 1px 0 0;
}

/* ]]> */
</style>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body style="font-family:Arial, Helvetica, sans-serif">
<table 
<?php
$totalExp = 0;
$caResult = new Model_DbTable_Cashaccount_Auditresult();
	if($this->showDetail){
		echo 'width="2500"';
		}
?>
 border="1" cellspacing="0" cellpadding="0" style="font-size:12px;">
  <tr>
    <td rowspan="3">Shop</td>
    <?php 
	date_default_timezone_set("Australia/Melbourne");
	
	if($this->showDetail){
	foreach($this->dateArr as $dtc){ ?>
    <td colspan="2"> <?php echo $dtc; echo "    [".date("D",strtotime($dtc))."]"; ?>
    </td>
    <?php 
	}
	 }?>
    <td colspan="4">Cash Account System </td>
    <td colspan="5">Actual Receiving Total [<a href="
    <?php echo $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";?>/showdetail/yes
    
    
    ">Show Actual Receiving Details</a>]</td>
    <td rowspan="3">APOS Total Sales</td>
    <td rowspan="3">Shop</td>
    <td rowspan="3">Type</td>
    <td rowspan="3">Bank</td>
    <td rowspan="3">Cash</td>
    <td rowspan="3">TypeA<br />
      Status</td>
    <td rowspan="3" align="center" style="width:100px;">Action<br />
      Request</td>
   
   <!-- <td rowspan="3" align="center" style="width:300px;">Confirm<br />
      &amp; Comment</td>-->
  </tr>
  <tr>
  	<?php 
	if($this->showDetail){
	for($i=0;$i<7;$i++){?>   
    <td rowspan="2" style="width:80px;">Bank In</td>
    <td rowspan="2" style="width:80px;">Cash Out</td>
       <?php } }?> 
    
    <td colspan="2">Staff Input Cash</td>
    <td>Staff EFTPOS</td>
    <td>SubTotal</td>
    <td colspan="2">Actual Cash</td>
    <td>Actual EFTPOS</td>
    <td>Exp</td>
    <td>SubTotal</td>
  </tr>
  <tr>
    <td>Bank In</td>
    <td>Cash Out</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>Bank In</td>
    <td>Cash Out</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
<?php 

foreach($this->arrCaList as $shop =>$v) {
	$allBankInCf = true;
	$allCashOutCf = true;
	?>  
  <tr>
    <td><?php echo $shop?></td>
	<?php
	if($this->showDetail){
	 foreach($v["detail"] as $key=> $vd){?>    
    <td style="font-size:12px;" <?php echo ($vd[0] >0 && $vd[1]!=1 && $vd[1]!=2 && $vd[1]!=3 )?'bgcolor="#CC9900"':''; ?>  ><?php echo ($vd[0] > 0)?" $ {$vd[0]}":" - ";?>
    <?php if($vd[0] >0 || $vd[2] >0){ ?>
    [<?php 
	switch($vd[1]){
		case(1):{echo "V";break;}
		case(2): {echo "X"; echo "<br /> [$ {$vd[2]}]";break;}
		case(3): {echo "Fill:[$ {$vd[2]}]"; break;}
		default: {echo "?";$allBankInCf = false;break;}
		}
	?>]
    <?php }?>
    </td>
    <td style="font-size:12px;" <?php echo ($vd[3]>0 && $vd[4]!=1 && $vd[4]!=2 &&$vd[4]!=3  )?'bgcolor="#CC9900"':''; ?>><?php echo ($vd[3] > 0)?" $ {$vd[3]}":" - ";?>
    <?php if($vd[3] >0 || $vd[5] >0 ){ ?>
    [<?php 
	switch($vd[4]){
		case(1):{echo "V";break;}
		case(2): {echo "X"; echo "<br /> [$ {$vd[5]}]";break;}
		case(3): {echo "Fill:[$ {$vd[5]}]"; break;}
		default: {echo "?"; $allCashOutCf = false; break;}
		}
	?>]
    <?php }?>
    </td>
     <?php } }?>     
    <td><?php echo ($v["bankin_total"] > 0)? "$ {$v['bankin_total']}":" - "?>
    
    </td>
    <td><?php echo ($v["cashout_total"] > 0)? "$ {$v['cashout_total']}":" - "?></td>
    <td
	<?php 

	
	?>
    ><?php echo ($v["eft_total"] > 0)? "$ {$v['eft_total']}":" - "?></td>
    <td
	<?php 
	$staffInputTotal = $v["bankin_total"] + $v["cashout_total"] + $v["eft_total"] + $v["total_expense"] ;
	/*
	if(abs($v["eft_total"] -  $v["total_cb_eft"] ) > 0.04){
		echo ' bgcolor="#FF6666"';
		}
	else{
		echo ' bgcolor="#80FF80"';
		}	
	*/
	?>
    style=" background-color:#CCC;"
    > $ 
    <?php 
	 echo $staffInputTotal;
	?>
    </td>
    <td><?php echo ($v["confirmed_bankin"] > 0)? "$ {$v['confirmed_bankin']}":" - "?></td>
    <td><?php echo ($v["confirmed_cashout"] > 0)? "$ {$v['confirmed_cashout']}":" - "?></td>
    <td
    	<?php 

	
	?>
    
    >
	<?php echo ($v["total_cb_eft"] > 0)? "$ {$v['total_cb_eft']}":" - "?>
    </td>
    <td
    	<?php 

	
	?>
    
    ><?php echo $v["total_expense"];
	$totalExp += $v["total_expense"];
	
	?></td>
    <td
    <?php 
	$totalActReceive = $v["confirmed_bankin"] + $v["confirmed_cashout"] + $v["total_cb_eft"] + $v["total_expense"];
	
	?>
    style=" background-color:#CCC;"
    > $ <?php  echo $totalActReceive; echo "(".round($totalActReceive - $v['total_apos_sales'],2).")"?></td>
    <td ><?php echo ($v["total_apos_sales"] > 0)? "$ {$v['total_apos_sales']}":" - "?> 
    </td>
    <td ><?php echo $shop?></td>
    <td <?php
    $theDiff = abs($staffInputTotal - $v["total_apos_sales"]);
	$aDiff = abs( $v["total_apos_sales"] - $totalActReceive );
	$type = "";
	if($theDiff >0.04){
		//echo ' bgcolor="#CC3300"';
		$type = "B";
		}
	else{
		if($aDiff <0.04){
			//echo 'bgcolor="#006600"';
		}
		else{
			//echo ' bgcolor="#CC3300"';
			}
		$type = "A";
		}	
	
	?> ><?php echo $type;?></td>
    <td ><?php echo ($allBankInCf)?'<img src="/im/yes20.jpg" />':'<img src="/im/no20.jpg" />';?></td>
    <td ><?php echo ($allCashOutCf)?'<img src="/im/yes20.jpg" />':'<img src="/im/no20.jpg" />';?></td>
    <td ><?

    if($type == "A"){
		if($allBankInCf && $allCashOutCf){
			
			 echo ($aDiff<=0.04)?'<img src="/im/yes20.jpg" />':'<img src="/im/no20.jpg" />';
			}
		else{
			echo "Incomplete";	
		}	
		}else{
			
		echo " - ";	
		}
	
	?></td>
    <td ><?
    if($type == "A" && $aDiff <= 0.04 ){
		echo 'Pass <img src="/im/yes20.jpg" />';
		}
		else{
		echo 'Check <img src="/im/no20.jpg" />';	
		}
	
	?></td>
    <!--
    <td >
    
	<?php
	 $caResList = $caResult->getAuditByShopByDate($shop,$this->dateBegin);
	// var_dump($caResList);
	?>
	
    <table width="100%" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <th scope="col" style="width:50px;">Status</th>
        <th scope="col">Comment</th>
        </tr>
    <?php 
	if(!empty($caResList)){
	foreach($caResList as $k=>$v){?>    
      <tr>
        <td><?php
        switch($v["audit_pass"]){
			case(1):{echo "Passed";break;}
			case(2):{echo "Need Follow";break;}
			case(9):{echo "Closed";break;}
			}
		?></td>
        <td><?php echo $v["audit_comment"]?></td>
        </tr>
    <?php } } else {?>
    <tr>
    <td colspan="2"> - </td>
    </tr>
    <?php }?>    
      <tr>
        <td colspan="2">
        <form method="post">
          <select name="status" id="select">
            <option value="0" selected="selected">Not Decide</option>
            <option value="1" >Confirm Pass</option>
            <option value="2">Follw Up</option>
            <option value="9">Case Close</option>
          </select>
          <label for="staff_name"></label>
          <input name="staff_name" type="text" id="staff_name" value="Auditer" />
          <br />
          <textarea name="comment" cols="40" rows="2" id="textfield"></textarea>
         <input name="shop_code" type="hidden" value="<?php echo $shop;?>" />
         <input name="date" type="hidden" value="<?php echo $this->dateBegin;?>" />
          <input type="submit" name="button" id="button" value="Save Status" />
        </form>
          </td>
        </tr>
    </table>
   
    </td>
     -->
  </tr>
<?php } ?>  
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><?php echo $totalExp;?></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>  
</table>

<br />
Missing Opening / Closing :<br />
<?php 
foreach($this->arrMissing as $vm){
	echo "{$vm[0]} {$vm[1]} {$vm[2]}<br />";
	}
?>

</body>
</html>
